<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>7.3 常用函数 | 商业数据分析师-R 语言数据处理</title>
  <meta name="description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  <meta name="generator" content="bookdown 0.22 and GitBook 2.6.7" />

  <meta property="og:title" content="7.3 常用函数 | 商业数据分析师-R 语言数据处理" />
  <meta property="og:type" content="book" />
  
  
  <meta property="og:description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="7.3 常用函数 | 商业数据分析师-R 语言数据处理" />
  
  <meta name="twitter:description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  

<meta name="author" content="Yufei Zhong" />


<meta name="date" content="2021-06-23" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="datatable-usage.html"/>
<link rel="next" href="datatable-advanced-functions.html"/>
<script src="libs/header-attrs-2.8/header-attrs.js"></script>
<script src="libs/jquery-3.5.1/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />









<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<link href="libs/tabwid-1.0.0/tabwid.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.5.3/htmlwidgets.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.18/datatables.js"></script>
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk-1.1.1/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.1.1/js/crosstalk.min.js"></script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>


<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">R学习笔记</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>欢迎</a>
<ul>
<li class="chapter" data-level="" data-path="abstract.html"><a href="abstract.html"><i class="fa fa-check"></i>内容概要</a></li>
<li class="chapter" data-level="" data-path="sec-licenses.html"><a href="sec-licenses.html"><i class="fa fa-check"></i>授权说明</a></li>
<li class="chapter" data-level="" data-path="session.html"><a href="session.html"><i class="fa fa-check"></i>运行信息</a></li>
<li class="chapter" data-level="" data-path="author.html"><a href="author.html"><i class="fa fa-check"></i>关于本人</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="data-read-write-description.html"><a href="data-read-write-description.html"><i class="fa fa-check"></i><b>1</b> 数据导入导出</a>
<ul>
<li class="chapter" data-level="1.1" data-path="readxl-description.html"><a href="readxl-description.html"><i class="fa fa-check"></i><b>1.1</b> readxl</a>
<ul>
<li class="chapter" data-level="1.1.1" data-path="readxl-description.html"><a href="readxl-description.html#readxl:install"><i class="fa fa-check"></i><b>1.1.1</b> 安装</a></li>
<li class="chapter" data-level="1.1.2" data-path="readxl-description.html"><a href="readxl-description.html#readxl:usage"><i class="fa fa-check"></i><b>1.1.2</b> 用法</a></li>
<li class="chapter" data-level="1.1.3" data-path="readxl-description.html"><a href="readxl-description.html#batch:read"><i class="fa fa-check"></i><b>1.1.3</b> 批量读取</a></li>
<li class="chapter" data-level="1.1.4" data-path="readxl-description.html"><a href="readxl-description.html#batch:write"><i class="fa fa-check"></i><b>1.1.4</b> 批量输出</a></li>
</ul></li>
<li class="chapter" data-level="1.2" data-path="writexl.html"><a href="writexl.html"><i class="fa fa-check"></i><b>1.2</b> writexl</a>
<ul>
<li class="chapter" data-level="1.2.1" data-path="writexl.html"><a href="writexl.html#writexl:usage"><i class="fa fa-check"></i><b>1.2.1</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path="openxlsx-description.html"><a href="openxlsx-description.html"><i class="fa fa-check"></i><b>1.3</b> openxlsx</a>
<ul>
<li class="chapter" data-level="1.3.1" data-path="openxlsx-description.html"><a href="openxlsx-description.html#openxlsx:install"><i class="fa fa-check"></i><b>1.3.1</b> 安装</a></li>
<li class="chapter" data-level="1.3.2" data-path="openxlsx-description.html"><a href="openxlsx-description.html#openxlsx:functions"><i class="fa fa-check"></i><b>1.3.2</b> 基础功能</a></li>
<li class="chapter" data-level="1.3.3" data-path="openxlsx-description.html"><a href="openxlsx-description.html#定制格式输出"><i class="fa fa-check"></i><b>1.3.3</b> 定制格式输出</a></li>
<li class="chapter" data-level="1.3.4" data-path="openxlsx-description.html"><a href="openxlsx-description.html#函数参数"><i class="fa fa-check"></i><b>1.3.4</b> 函数参数</a></li>
<li class="chapter" data-level="1.3.5" data-path="openxlsx-description.html"><a href="openxlsx-description.html#总结"><i class="fa fa-check"></i><b>1.3.5</b> 总结</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path="readr-package.html"><a href="readr-package.html"><i class="fa fa-check"></i><b>1.4</b> readr</a>
<ul>
<li class="chapter" data-level="1.4.1" data-path="readr-package.html"><a href="readr-package.html#readr:install"><i class="fa fa-check"></i><b>1.4.1</b> 安装</a></li>
<li class="chapter" data-level="1.4.2" data-path="readr-package.html"><a href="readr-package.html#readr:usage"><i class="fa fa-check"></i><b>1.4.2</b> 用法</a></li>
<li class="chapter" data-level="1.4.3" data-path="readr-package.html"><a href="readr-package.html#readr:write-function"><i class="fa fa-check"></i><b>1.4.3</b> 导出功能</a></li>
<li class="chapter" data-level="1.4.4" data-path="readr-package.html"><a href="readr-package.html#总结-1"><i class="fa fa-check"></i><b>1.4.4</b> 总结</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="data-vroom.html"><a href="data-vroom.html"><i class="fa fa-check"></i><b>1.5</b> vroom</a>
<ul>
<li class="chapter" data-level="1.5.1" data-path="data-vroom.html"><a href="data-vroom.html#安装"><i class="fa fa-check"></i><b>1.5.1</b> 安装</a></li>
<li class="chapter" data-level="1.5.2" data-path="data-vroom.html"><a href="data-vroom.html#用法"><i class="fa fa-check"></i><b>1.5.2</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="1.6" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html"><i class="fa fa-check"></i><b>1.6</b> Rstudio导入</a>
<ul>
<li class="chapter" data-level="1.6.1" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html#rstudio-工具栏导入"><i class="fa fa-check"></i><b>1.6.1</b> rstudio 工具栏导入</a></li>
<li class="chapter" data-level="1.6.2" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html#插件导入"><i class="fa fa-check"></i><b>1.6.2</b> 插件导入</a></li>
</ul></li>
<li class="chapter" data-level="1.7" data-path="data-file-path.html"><a href="data-file-path.html"><i class="fa fa-check"></i><b>1.7</b> 文件路径</a>
<ul>
<li class="chapter" data-level="1.7.1" data-path="data-file-path.html"><a href="data-file-path.html#指定路径"><i class="fa fa-check"></i><b>1.7.1</b> 指定路径</a></li>
<li class="chapter" data-level="1.7.2" data-path="data-file-path.html"><a href="data-file-path.html#默认路径"><i class="fa fa-check"></i><b>1.7.2</b> 默认路径</a></li>
</ul></li>
<li class="chapter" data-level="1.8" data-path="data-expand.html"><a href="data-expand.html"><i class="fa fa-check"></i><b>1.8</b> 拓展</a>
<ul>
<li class="chapter" data-level="1.8.1" data-path="data-expand.html"><a href="data-expand.html#tidyxl:package"><i class="fa fa-check"></i><b>1.8.1</b> tidyxl</a></li>
<li class="chapter" data-level="1.8.2" data-path="data-expand.html"><a href="data-expand.html#参考资料"><i class="fa fa-check"></i><b>1.8.2</b> 参考资料</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Data-Manipulation-dplyr.html"><a href="Data-Manipulation-dplyr.html"><i class="fa fa-check"></i><b>2</b> 数据处理之-dplyr</a>
<ul>
<li class="chapter" data-level="2.1" data-path="dplyr-description.html"><a href="dplyr-description.html"><i class="fa fa-check"></i><b>2.1</b> 前言</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="dplyr-description.html"><a href="dplyr-description.html#dplyr:install-package"><i class="fa fa-check"></i><b>2.1.1</b> 安装</a></li>
<li class="chapter" data-level="2.1.2" data-path="dplyr-description.html"><a href="dplyr-description.html#dplyr:difference-of-sql"><i class="fa fa-check"></i><b>2.1.2</b> Excel and Sql 类比</a></li>
<li class="chapter" data-level="2.1.3" data-path="dplyr-description.html"><a href="dplyr-description.html#常见问题"><i class="fa fa-check"></i><b>2.1.3</b> 常见问题</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="dplyr-usage.html"><a href="dplyr-usage.html"><i class="fa fa-check"></i><b>2.2</b> 基础用法</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-filter"><i class="fa fa-check"></i><b>2.2.1</b> filter</a></li>
<li class="chapter" data-level="2.2.2" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-select"><i class="fa fa-check"></i><b>2.2.2</b> select</a></li>
<li class="chapter" data-level="2.2.3" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-rename"><i class="fa fa-check"></i><b>2.2.3</b> rename</a></li>
<li class="chapter" data-level="2.2.4" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-relocate"><i class="fa fa-check"></i><b>2.2.4</b> relocate</a></li>
<li class="chapter" data-level="2.2.5" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-mutate"><i class="fa fa-check"></i><b>2.2.5</b> mutate</a></li>
<li class="chapter" data-level="2.2.6" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-arrange"><i class="fa fa-check"></i><b>2.2.6</b> arrange</a></li>
<li class="chapter" data-level="2.2.7" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-summarise"><i class="fa fa-check"></i><b>2.2.7</b> summarise</a></li>
<li class="chapter" data-level="2.2.8" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-groupby"><i class="fa fa-check"></i><b>2.2.8</b> group_by</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="dplyr-functions.html"><a href="dplyr-functions.html"><i class="fa fa-check"></i><b>2.3</b> 常用函数</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="dplyr-functions.html"><a href="dplyr-functions.html#条件判断"><i class="fa fa-check"></i><b>2.3.1</b> 条件判断</a></li>
<li class="chapter" data-level="2.3.2" data-path="dplyr-functions.html"><a href="dplyr-functions.html#case_when"><i class="fa fa-check"></i><b>2.3.2</b> case_when</a></li>
<li class="chapter" data-level="2.3.3" data-path="dplyr-functions.html"><a href="dplyr-functions.html#计数函数"><i class="fa fa-check"></i><b>2.3.3</b> 计数函数</a></li>
<li class="chapter" data-level="2.3.4" data-path="dplyr-functions.html"><a href="dplyr-functions.html#排序函数"><i class="fa fa-check"></i><b>2.3.4</b> 排序函数</a></li>
<li class="chapter" data-level="2.3.5" data-path="dplyr-functions.html"><a href="dplyr-functions.html#提取向量"><i class="fa fa-check"></i><b>2.3.5</b> 提取向量</a></li>
<li class="chapter" data-level="2.3.6" data-path="dplyr-functions.html"><a href="dplyr-functions.html#dplyr:slice"><i class="fa fa-check"></i><b>2.3.6</b> slice 系列</a></li>
<li class="chapter" data-level="2.3.7" data-path="dplyr-functions.html"><a href="dplyr-functions.html#group-系列"><i class="fa fa-check"></i><b>2.3.7</b> group 系列</a></li>
<li class="chapter" data-level="2.3.8" data-path="dplyr-functions.html"><a href="dplyr-functions.html#其它函数"><i class="fa fa-check"></i><b>2.3.8</b> 其它函数</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html"><i class="fa fa-check"></i><b>2.4</b> 表关联</a>
<ul>
<li class="chapter" data-level="2.4.1" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html#dplyr:merge-table-usage"><i class="fa fa-check"></i><b>2.4.1</b> 两表关联</a></li>
<li class="chapter" data-level="2.4.2" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html#dplyr:merge-multiple-table"><i class="fa fa-check"></i><b>2.4.2</b> 多表操作</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html"><i class="fa fa-check"></i><b>2.5</b> 分组操作</a>
<ul>
<li class="chapter" data-level="2.5.1" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#添加分组"><i class="fa fa-check"></i><b>2.5.1</b> 添加分组</a></li>
<li class="chapter" data-level="2.5.2" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#查看分组"><i class="fa fa-check"></i><b>2.5.2</b> 查看分组</a></li>
<li class="chapter" data-level="2.5.3" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#更改和添加分组变量"><i class="fa fa-check"></i><b>2.5.3</b> 更改和添加分组变量</a></li>
<li class="chapter" data-level="2.5.4" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#删除分组变量"><i class="fa fa-check"></i><b>2.5.4</b> 删除分组变量</a></li>
<li class="chapter" data-level="2.5.5" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#动词影响"><i class="fa fa-check"></i><b>2.5.5</b> 动词影响</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html"><i class="fa fa-check"></i><b>2.6</b> 列操作</a>
<ul>
<li class="chapter" data-level="2.6.1" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#dplyr-column-manipulation-basic-usage"><i class="fa fa-check"></i><b>2.6.1</b> 基础用法</a></li>
<li class="chapter" data-level="2.6.2" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#多种函数功能"><i class="fa fa-check"></i><b>2.6.2</b> 多种函数功能</a></li>
<li class="chapter" data-level="2.6.3" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#当前列"><i class="fa fa-check"></i><b>2.6.3</b> 当前列</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html"><i class="fa fa-check"></i><b>2.7</b> 行操作</a>
<ul>
<li class="chapter" data-level="2.7.1" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html#比较差异"><i class="fa fa-check"></i><b>2.7.1</b> 比较差异</a></li>
<li class="chapter" data-level="2.7.2" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html#常用案例"><i class="fa fa-check"></i><b>2.7.2</b> 常用案例</a></li>
</ul></li>
<li class="chapter" data-level="2.8" data-path="dplyr-programming.html"><a href="dplyr-programming.html"><i class="fa fa-check"></i><b>2.8</b> <code>dplyr</code>编程</a>
<ul>
<li class="chapter" data-level="2.8.1" data-path="dplyr-programming.html"><a href="dplyr-programming.html#案例"><i class="fa fa-check"></i><b>2.8.1</b> 案例</a></li>
</ul></li>
<li class="chapter" data-level="2.9" data-path="dplyr-reference-material.html"><a href="dplyr-reference-material.html"><i class="fa fa-check"></i><b>2.9</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Data-tidyr-package.html"><a href="Data-tidyr-package.html"><i class="fa fa-check"></i><b>3</b> 整洁数据之 tidyr</a>
<ul>
<li class="chapter" data-level="3.1" data-path="tidyr-useage.html"><a href="tidyr-useage.html"><i class="fa fa-check"></i><b>3.1</b> tidyr 介绍</a>
<ul>
<li class="chapter" data-level="3.1.1" data-path="tidyr-useage.html"><a href="tidyr-useage.html#tidyr:install"><i class="fa fa-check"></i><b>3.1.1</b> 安装</a></li>
<li class="chapter" data-level="3.1.2" data-path="tidyr-useage.html"><a href="tidyr-useage.html#tidyr:functions"><i class="fa fa-check"></i><b>3.1.2</b> 主要功能</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="pivoting.html"><a href="pivoting.html"><i class="fa fa-check"></i><b>3.2</b> 长宽转换</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="pivoting.html"><a href="pivoting.html#宽转长"><i class="fa fa-check"></i><b>3.2.1</b> 宽转长</a></li>
<li class="chapter" data-level="3.2.2" data-path="pivoting.html"><a href="pivoting.html#用法-1"><i class="fa fa-check"></i><b>3.2.2</b> 用法</a></li>
<li class="chapter" data-level="3.2.3" data-path="pivoting.html"><a href="pivoting.html#长转宽"><i class="fa fa-check"></i><b>3.2.3</b> 长转宽</a></li>
<li class="chapter" data-level="3.2.4" data-path="pivoting.html"><a href="pivoting.html#用法-2"><i class="fa fa-check"></i><b>3.2.4</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="tidyr-rectangle.html"><a href="tidyr-rectangle.html"><i class="fa fa-check"></i><b>3.3</b> 矩形数据</a></li>
<li class="chapter" data-level="3.4" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html"><i class="fa fa-check"></i><b>3.4</b> 嵌套数据</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html#基础"><i class="fa fa-check"></i><b>3.4.1</b> 基础</a></li>
<li class="chapter" data-level="3.4.2" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html#嵌套数据和模型"><i class="fa fa-check"></i><b>3.4.2</b> 嵌套数据和模型</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="character-vector.html"><a href="character-vector.html"><i class="fa fa-check"></i><b>3.5</b> 字符处理</a>
<ul>
<li class="chapter" data-level="3.5.1" data-path="character-vector.html"><a href="character-vector.html#新列提取"><i class="fa fa-check"></i><b>3.5.1</b> 新列提取</a></li>
<li class="chapter" data-level="3.5.2" data-path="character-vector.html"><a href="character-vector.html#拆分"><i class="fa fa-check"></i><b>3.5.2</b> 拆分</a></li>
<li class="chapter" data-level="3.5.3" data-path="character-vector.html"><a href="character-vector.html#列拆分行"><i class="fa fa-check"></i><b>3.5.3</b> 列拆分行</a></li>
<li class="chapter" data-level="3.5.4" data-path="character-vector.html"><a href="character-vector.html#合并多列"><i class="fa fa-check"></i><b>3.5.4</b> 合并多列</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="tidyr-expand.html"><a href="tidyr-expand.html"><i class="fa fa-check"></i><b>3.6</b> 扩展数据框</a></li>
<li class="chapter" data-level="3.7" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html"><i class="fa fa-check"></i><b>3.7</b> 缺失值</a>
<ul>
<li class="chapter" data-level="3.7.1" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#replace_na"><i class="fa fa-check"></i><b>3.7.1</b> replace_na</a></li>
<li class="chapter" data-level="3.7.2" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#fill"><i class="fa fa-check"></i><b>3.7.2</b> fill</a></li>
<li class="chapter" data-level="3.7.3" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#drop_na"><i class="fa fa-check"></i><b>3.7.3</b> drop_na</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="character-handling.html"><a href="character-handling.html"><i class="fa fa-check"></i><b>4</b> 字符处理</a>
<ul>
<li class="chapter" data-level="4.1" data-path="character-base-R.html"><a href="character-base-R.html"><i class="fa fa-check"></i><b>4.1</b> base R</a>
<ul>
<li class="chapter" data-level="4.1.1" data-path="character-base-R.html"><a href="character-base-R.html#单双引号"><i class="fa fa-check"></i><b>4.1.1</b> 单双引号</a></li>
<li class="chapter" data-level="4.1.2" data-path="character-base-R.html"><a href="character-base-R.html#转义"><i class="fa fa-check"></i><b>4.1.2</b> 转义</a></li>
<li class="chapter" data-level="4.1.3" data-path="character-base-R.html"><a href="character-base-R.html#常用函数"><i class="fa fa-check"></i><b>4.1.3</b> 常用函数</a></li>
<li class="chapter" data-level="4.1.4" data-path="character-base-R.html"><a href="character-base-R.html#newfeatures"><i class="fa fa-check"></i><b>4.1.4</b> 新特性</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html"><i class="fa fa-check"></i><b>4.2</b> stringr</a>
<ul>
<li class="chapter" data-level="4.2.1" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-install"><i class="fa fa-check"></i><b>4.2.1</b> 安装</a></li>
<li class="chapter" data-level="4.2.2" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-usage"><i class="fa fa-check"></i><b>4.2.2</b> 基本使用</a></li>
<li class="chapter" data-level="4.2.3" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-functions"><i class="fa fa-check"></i><b>4.2.3</b> 常用函数</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="character-application.html"><a href="character-application.html"><i class="fa fa-check"></i><b>4.3</b> 综合运用</a>
<ul>
<li class="chapter" data-level="4.3.1" data-path="character-application.html"><a href="character-application.html#实现excel函数"><i class="fa fa-check"></i><b>4.3.1</b> 实现excel函数</a></li>
<li class="chapter" data-level="4.3.2" data-path="character-application.html"><a href="character-application.html#使用案例"><i class="fa fa-check"></i><b>4.3.2</b> 使用案例</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="character-the-difference-stringr-and-base.html"><a href="character-the-difference-stringr-and-base.html"><i class="fa fa-check"></i><b>4.4</b> base 和 stringr</a></li>
<li class="chapter" data-level="4.5" data-path="character-reference-material.html"><a href="character-reference-material.html"><i class="fa fa-check"></i><b>4.5</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="datetime.html"><a href="datetime.html"><i class="fa fa-check"></i><b>5</b> 时间处理</a>
<ul>
<li class="chapter" data-level="5.1" data-path="datetime-base-R.html"><a href="datetime-base-R.html"><i class="fa fa-check"></i><b>5.1</b> base R</a>
<ul>
<li class="chapter" data-level="5.1.1" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-date-class"><i class="fa fa-check"></i><b>5.1.1</b> Date</a></li>
<li class="chapter" data-level="5.1.2" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-POSIXct-class"><i class="fa fa-check"></i><b>5.1.2</b> POSIXct</a></li>
<li class="chapter" data-level="5.1.3" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-POSIXlt-class"><i class="fa fa-check"></i><b>5.1.3</b> POSIXlt</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="lubridate.html"><a href="lubridate.html"><i class="fa fa-check"></i><b>5.2</b> lubridate</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="lubridate.html"><a href="lubridate.html#lubridate-install"><i class="fa fa-check"></i><b>5.2.1</b> 安装包</a></li>
<li class="chapter" data-level="5.2.2" data-path="lubridate.html"><a href="lubridate.html#get-current-datetime"><i class="fa fa-check"></i><b>5.2.2</b> 当前时间日期</a></li>
<li class="chapter" data-level="5.2.3" data-path="lubridate.html"><a href="lubridate.html#make-datetime"><i class="fa fa-check"></i><b>5.2.3</b> 构造日期时间</a></li>
<li class="chapter" data-level="5.2.4" data-path="lubridate.html"><a href="lubridate.html#parse-datetime"><i class="fa fa-check"></i><b>5.2.4</b> 解析日期时间</a></li>
<li class="chapter" data-level="5.2.5" data-path="lubridate.html"><a href="lubridate.html#extracting-datetime-information"><i class="fa fa-check"></i><b>5.2.5</b> 提取日期时间成分</a></li>
<li class="chapter" data-level="5.2.6" data-path="lubridate.html"><a href="lubridate.html#time-zones"><i class="fa fa-check"></i><b>5.2.6</b> 处理时区</a></li>
<li class="chapter" data-level="5.2.7" data-path="lubridate.html"><a href="lubridate.html#interveal"><i class="fa fa-check"></i><b>5.2.7</b> 时间间隔</a></li>
<li class="chapter" data-level="5.2.8" data-path="lubridate.html"><a href="lubridate.html#calculate-datetime"><i class="fa fa-check"></i><b>5.2.8</b> 时间日期计算</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="datetime-application.html"><a href="datetime-application.html"><i class="fa fa-check"></i><b>5.3</b> 综合运用</a>
<ul>
<li class="chapter" data-level="5.3.1" data-path="datetime-application.html"><a href="datetime-application.html#日报同环比计算"><i class="fa fa-check"></i><b>5.3.1</b> 日报同环比计算</a></li>
<li class="chapter" data-level="5.3.2" data-path="datetime-application.html"><a href="datetime-application.html#清洗不同类型日期格式"><i class="fa fa-check"></i><b>5.3.2</b> 清洗不同类型日期格式</a></li>
<li class="chapter" data-level="5.3.3" data-path="datetime-application.html"><a href="datetime-application.html#扫码后中奖时间匹配"><i class="fa fa-check"></i><b>5.3.3</b> 扫码后中奖时间匹配</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html"><i class="fa fa-check"></i><b>5.4</b> 补充资料</a>
<ul>
<li class="chapter" data-level="5.4.1" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html#excel-and-r"><i class="fa fa-check"></i><b>5.4.1</b> Excel and R</a></li>
<li class="chapter" data-level="5.4.2" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html#参考资料-1"><i class="fa fa-check"></i><b>5.4.2</b> 参考资料</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="forcats.html"><a href="forcats.html"><i class="fa fa-check"></i><b>6</b> 因子介绍</a>
<ul>
<li class="chapter" data-level="6.1" data-path="forcats-introduction.html"><a href="forcats-introduction.html"><i class="fa fa-check"></i><b>6.1</b> 介绍</a>
<ul>
<li class="chapter" data-level="6.1.1" data-path="forcats-introduction.html"><a href="forcats-introduction.html#forcats:install"><i class="fa fa-check"></i><b>6.1.1</b> 安装</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="forcats-usage.html"><a href="forcats-usage.html"><i class="fa fa-check"></i><b>6.2</b> 用法</a>
<ul>
<li class="chapter" data-level="6.2.1" data-path="forcats-usage.html"><a href="forcats-usage.html#创建因子"><i class="fa fa-check"></i><b>6.2.1</b> 创建因子</a></li>
<li class="chapter" data-level="6.2.2" data-path="forcats-usage.html"><a href="forcats-usage.html#修改因子顺序"><i class="fa fa-check"></i><b>6.2.2</b> 修改因子顺序</a></li>
<li class="chapter" data-level="6.2.3" data-path="forcats-usage.html"><a href="forcats-usage.html#修改因子级别"><i class="fa fa-check"></i><b>6.2.3</b> 修改因子级别</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Data-Manipulation-datatable.html"><a href="Data-Manipulation-datatable.html"><i class="fa fa-check"></i><b>7</b> data.table</a>
<ul>
<li class="chapter" data-level="7.1" data-path="datatable-description.html"><a href="datatable-description.html"><i class="fa fa-check"></i><b>7.1</b> 基础介绍</a>
<ul>
<li class="chapter" data-level="7.1.1" data-path="datatable-description.html"><a href="datatable-description.html#读取数据"><i class="fa fa-check"></i><b>7.1.1</b> 读取数据</a></li>
<li class="chapter" data-level="7.1.2" data-path="datatable-description.html"><a href="datatable-description.html#基本格式"><i class="fa fa-check"></i><b>7.1.2</b> 基本格式</a></li>
<li class="chapter" data-level="7.1.3" data-path="datatable-description.html"><a href="datatable-description.html#i-j-by-使用"><i class="fa fa-check"></i><b>7.1.3</b> i j by 使用</a></li>
<li class="chapter" data-level="7.1.4" data-path="datatable-description.html"><a href="datatable-description.html#行列筛选总结"><i class="fa fa-check"></i><b>7.1.4</b> 行列筛选总结</a></li>
</ul></li>
<li class="chapter" data-level="7.2" data-path="datatable-usage.html"><a href="datatable-usage.html"><i class="fa fa-check"></i><b>7.2</b> 常规操作</a>
<ul>
<li class="chapter" data-level="7.2.1" data-path="datatable-usage.html"><a href="datatable-usage.html#行筛选"><i class="fa fa-check"></i><b>7.2.1</b> 行筛选</a></li>
<li class="chapter" data-level="7.2.2" data-path="datatable-usage.html"><a href="datatable-usage.html#新增更新列"><i class="fa fa-check"></i><b>7.2.2</b> 新增更新列</a></li>
<li class="chapter" data-level="7.2.3" data-path="datatable-usage.html"><a href="datatable-usage.html#排序"><i class="fa fa-check"></i><b>7.2.3</b> 排序</a></li>
</ul></li>
<li class="chapter" data-level="7.3" data-path="datatable-function.html"><a href="datatable-function.html"><i class="fa fa-check"></i><b>7.3</b> 常用函数</a>
<ul>
<li class="chapter" data-level="7.3.1" data-path="datatable-function.html"><a href="datatable-function.html#特殊符号"><i class="fa fa-check"></i><b>7.3.1</b> 特殊符号</a></li>
<li class="chapter" data-level="7.3.2" data-path="datatable-function.html"><a href="datatable-function.html#排序函数-1"><i class="fa fa-check"></i><b>7.3.2</b> 排序函数</a></li>
<li class="chapter" data-level="7.3.3" data-path="datatable-function.html"><a href="datatable-function.html#非重复计数"><i class="fa fa-check"></i><b>7.3.3</b> 非重复计数</a></li>
<li class="chapter" data-level="7.3.4" data-path="datatable-function.html"><a href="datatable-function.html#判断函数"><i class="fa fa-check"></i><b>7.3.4</b> 判断函数</a></li>
<li class="chapter" data-level="7.3.5" data-path="datatable-function.html"><a href="datatable-function.html#交集-差集-合并"><i class="fa fa-check"></i><b>7.3.5</b> 交集 差集 合并</a></li>
<li class="chapter" data-level="7.3.6" data-path="datatable-function.html"><a href="datatable-function.html#长宽转换"><i class="fa fa-check"></i><b>7.3.6</b> 长宽转换</a></li>
<li class="chapter" data-level="7.3.7" data-path="datatable-function.html"><a href="datatable-function.html#表连接"><i class="fa fa-check"></i><b>7.3.7</b> 表连接</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html"><i class="fa fa-check"></i><b>7.4</b> 高级函数</a>
<ul>
<li class="chapter" data-level="7.4.1" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#groupingsets"><i class="fa fa-check"></i><b>7.4.1</b> groupingsets</a></li>
<li class="chapter" data-level="7.4.2" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#rleid"><i class="fa fa-check"></i><b>7.4.2</b> rleid</a></li>
<li class="chapter" data-level="7.4.3" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#shift"><i class="fa fa-check"></i><b>7.4.3</b> shift</a></li>
<li class="chapter" data-level="7.4.4" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#j"><i class="fa fa-check"></i><b>7.4.4</b> J</a></li>
</ul></li>
<li class="chapter" data-level="7.5" data-path="datatable-tips.html"><a href="datatable-tips.html"><i class="fa fa-check"></i><b>7.5</b> 小技巧</a>
<ul>
<li class="chapter" data-level="7.5.1" data-path="datatable-tips.html"><a href="datatable-tips.html#用抑制中间过程输出"><i class="fa fa-check"></i><b>7.5.1</b> 用{}抑制中间过程输出</a></li>
<li class="chapter" data-level="7.5.2" data-path="datatable-tips.html"><a href="datatable-tips.html#使用打印data.table"><i class="fa fa-check"></i><b>7.5.2</b> 使用[]打印data.table</a></li>
</ul></li>
<li class="chapter" data-level="7.6" data-path="datatable-application.html"><a href="datatable-application.html"><i class="fa fa-check"></i><b>7.6</b> 运用</a>
<ul>
<li class="chapter" data-level="7.6.1" data-path="datatable-application.html"><a href="datatable-application.html#自定义函数计算"><i class="fa fa-check"></i><b>7.6.1</b> 自定义函数计算</a></li>
<li class="chapter" data-level="7.6.2" data-path="datatable-application.html"><a href="datatable-application.html#带汇总的聚合运算"><i class="fa fa-check"></i><b>7.6.2</b> 带汇总的聚合运算</a></li>
<li class="chapter" data-level="7.6.3" data-path="datatable-application.html"><a href="datatable-application.html#行列转变"><i class="fa fa-check"></i><b>7.6.3</b> 行列转变</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="8" data-path="database.html"><a href="database.html"><i class="fa fa-check"></i><b>8</b> database</a>
<ul>
<li class="chapter" data-level="8.1" data-path="database-install.html"><a href="database-install.html"><i class="fa fa-check"></i><b>8.1</b> 安装数据库</a></li>
<li class="chapter" data-level="8.2" data-path="database-odbc-package.html"><a href="database-odbc-package.html"><i class="fa fa-check"></i><b>8.2</b> odbc包</a>
<ul>
<li class="chapter" data-level="8.2.1" data-path="database-odbc-package.html"><a href="database-odbc-package.html#安装包"><i class="fa fa-check"></i><b>8.2.1</b> 安装包</a></li>
<li class="chapter" data-level="8.2.2" data-path="database-odbc-package.html"><a href="database-odbc-package.html#驱动安装"><i class="fa fa-check"></i><b>8.2.2</b> 驱动安装</a></li>
<li class="chapter" data-level="8.2.3" data-path="database-odbc-package.html"><a href="database-odbc-package.html#连接数据库"><i class="fa fa-check"></i><b>8.2.3</b> 连接数据库</a></li>
<li class="chapter" data-level="8.2.4" data-path="database-odbc-package.html"><a href="database-odbc-package.html#读写数据库"><i class="fa fa-check"></i><b>8.2.4</b> 读写数据库</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="database-DBI-package.html"><a href="database-DBI-package.html"><i class="fa fa-check"></i><b>8.3</b> DBI包</a>
<ul>
<li class="chapter" data-level="8.3.1" data-path="database-DBI-package.html"><a href="database-DBI-package.html#安装-1"><i class="fa fa-check"></i><b>8.3.1</b> 安装</a></li>
<li class="chapter" data-level="8.3.2" data-path="database-DBI-package.html"><a href="database-DBI-package.html#连接数据库-1"><i class="fa fa-check"></i><b>8.3.2</b> 连接数据库</a></li>
<li class="chapter" data-level="8.3.3" data-path="database-DBI-package.html"><a href="database-DBI-package.html#读写数据库-1"><i class="fa fa-check"></i><b>8.3.3</b> 读写数据库</a></li>
<li class="chapter" data-level="8.3.4" data-path="database-DBI-package.html"><a href="database-DBI-package.html#其它函数介绍"><i class="fa fa-check"></i><b>8.3.4</b> 其它函数介绍</a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="database-else-package.html"><a href="database-else-package.html"><i class="fa fa-check"></i><b>8.4</b> 其他R包</a>
<ul>
<li class="chapter" data-level="8.4.1" data-path="database-else-package.html"><a href="database-else-package.html#rodbc包"><i class="fa fa-check"></i><b>8.4.1</b> RODBC包</a></li>
<li class="chapter" data-level="8.4.2" data-path="database-else-package.html"><a href="database-else-package.html#roracle包"><i class="fa fa-check"></i><b>8.4.2</b> ROracle包</a></li>
<li class="chapter" data-level="8.4.3" data-path="database-else-package.html"><a href="database-else-package.html#rmysql包"><i class="fa fa-check"></i><b>8.4.3</b> RMySQL包</a></li>
<li class="chapter" data-level="8.4.4" data-path="database-else-package.html"><a href="database-else-package.html#rsqlite"><i class="fa fa-check"></i><b>8.4.4</b> RSQLite</a></li>
</ul></li>
<li class="chapter" data-level="8.5" data-path="database-big-data.html"><a href="database-big-data.html"><i class="fa fa-check"></i><b>8.5</b> 大数据相关R包</a>
<ul>
<li class="chapter" data-level="8.5.1" data-path="database-big-data.html"><a href="database-big-data.html#sparklyr"><i class="fa fa-check"></i><b>8.5.1</b> sparklyr</a></li>
<li class="chapter" data-level="8.5.2" data-path="database-big-data.html"><a href="database-big-data.html#RClickhouse"><i class="fa fa-check"></i><b>8.5.2</b> RClickhouse</a></li>
</ul></li>
<li class="chapter" data-level="8.6" data-path="database-FAQ.html"><a href="database-FAQ.html"><i class="fa fa-check"></i><b>8.6</b> 常见问题</a>
<ul>
<li class="chapter" data-level="8.6.1" data-path="database-FAQ.html"><a href="database-FAQ.html#乱码问题"><i class="fa fa-check"></i><b>8.6.1</b> 乱码问题</a></li>
<li class="chapter" data-level="8.6.2" data-path="database-FAQ.html"><a href="database-FAQ.html#无法连接问题"><i class="fa fa-check"></i><b>8.6.2</b> 无法连接问题</a></li>
<li class="chapter" data-level="8.6.3" data-path="database-FAQ.html"><a href="database-FAQ.html#远程连接"><i class="fa fa-check"></i><b>8.6.3</b> 远程连接</a></li>
<li class="chapter" data-level="8.6.4" data-path="database-FAQ.html"><a href="database-FAQ.html#跳板机连接"><i class="fa fa-check"></i><b>8.6.4</b> 跳板机连接</a></li>
</ul></li>
<li class="chapter" data-level="8.7" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html"><i class="fa fa-check"></i><b>8.7</b> dbplyr</a>
<ul>
<li class="chapter" data-level="8.7.1" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#安装-2"><i class="fa fa-check"></i><b>8.7.1</b> 安装</a></li>
<li class="chapter" data-level="8.7.2" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#基础用法-1"><i class="fa fa-check"></i><b>8.7.2</b> 基础用法</a></li>
<li class="chapter" data-level="8.7.3" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#无法正确转化"><i class="fa fa-check"></i><b>8.7.3</b> 无法正确转化</a></li>
</ul></li>
<li class="chapter" data-level="8.8" data-path="database-reference-material.html"><a href="database-reference-material.html"><i class="fa fa-check"></i><b>8.8</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="R-loop-structure.html"><a href="R-loop-structure.html"><i class="fa fa-check"></i><b>9</b> 循环结构</a>
<ul>
<li class="chapter" data-level="9.1" data-path="R-loop-description.html"><a href="R-loop-description.html"><i class="fa fa-check"></i><b>9.1</b> R循环介绍</a>
<ul>
<li class="chapter" data-level="9.1.1" data-path="R-loop-description.html"><a href="R-loop-description.html#R:loop-example"><i class="fa fa-check"></i><b>9.1.1</b> 简单示例</a></li>
<li class="chapter" data-level="9.1.2" data-path="R-loop-description.html"><a href="R-loop-description.html#three:loop-structure"><i class="fa fa-check"></i><b>9.1.2</b> 循环结构</a></li>
<li class="chapter" data-level="9.1.3" data-path="R-loop-description.html"><a href="R-loop-description.html#loop:control"><i class="fa fa-check"></i><b>9.1.3</b> 循环控制</a></li>
<li class="chapter" data-level="9.1.4" data-path="R-loop-description.html"><a href="R-loop-description.html#嵌套循环"><i class="fa fa-check"></i><b>9.1.4</b> 嵌套循环</a></li>
</ul></li>
<li class="chapter" data-level="9.2" data-path="loop-changes.html"><a href="loop-changes.html"><i class="fa fa-check"></i><b>9.2</b> 循环变化</a>
<ul>
<li class="chapter" data-level="9.2.1" data-path="loop-changes.html"><a href="loop-changes.html#修改已有对象"><i class="fa fa-check"></i><b>9.2.1</b> 修改已有对象</a></li>
<li class="chapter" data-level="9.2.2" data-path="loop-changes.html"><a href="loop-changes.html#循环模式"><i class="fa fa-check"></i><b>9.2.2</b> 循环模式</a></li>
<li class="chapter" data-level="9.2.3" data-path="loop-changes.html"><a href="loop-changes.html#未知长度输出"><i class="fa fa-check"></i><b>9.2.3</b> 未知长度输出</a></li>
</ul></li>
<li class="chapter" data-level="9.3" data-path="apply-function.html"><a href="apply-function.html"><i class="fa fa-check"></i><b>9.3</b> apply系列函数</a>
<ul>
<li class="chapter" data-level="9.3.1" data-path="apply-function.html"><a href="apply-function.html#lapply"><i class="fa fa-check"></i><b>9.3.1</b> lapply 循环迭代</a></li>
<li class="chapter" data-level="9.3.2" data-path="apply-function.html"><a href="apply-function.html#sapply"><i class="fa fa-check"></i><b>9.3.2</b> sapply</a></li>
<li class="chapter" data-level="9.3.3" data-path="apply-function.html"><a href="apply-function.html#vapply"><i class="fa fa-check"></i><b>9.3.3</b> vapply 迭代安全函数</a></li>
<li class="chapter" data-level="9.3.4" data-path="apply-function.html"><a href="apply-function.html#apply"><i class="fa fa-check"></i><b>9.3.4</b> apply 多维数据</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="10" data-path="purrr-Iteration.html"><a href="purrr-Iteration.html"><i class="fa fa-check"></i><b>10</b> 循环迭代purrr介绍</a>
<ul>
<li class="chapter" data-level="10.1" data-path="安装-3.html"><a href="安装-3.html"><i class="fa fa-check"></i><b>10.1</b> 安装</a></li>
<li class="chapter" data-level="10.2" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html"><i class="fa fa-check"></i><b>10.2</b> 常规用法</a>
<ul>
<li class="chapter" data-level="10.2.1" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html#map-系列"><i class="fa fa-check"></i><b>10.2.1</b> map 系列</a></li>
<li class="chapter" data-level="10.2.2" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html#pmap-系列"><i class="fa fa-check"></i><b>10.2.2</b> pmap 系列</a></li>
</ul></li>
<li class="chapter" data-level="10.3" data-path="purrr-map.html"><a href="purrr-map.html"><i class="fa fa-check"></i><b>10.3</b> map系列函数</a>
<ul>
<li class="chapter" data-level="10.3.1" data-path="purrr-map.html"><a href="purrr-map.html#用法-3"><i class="fa fa-check"></i><b>10.3.1</b> 用法</a></li>
<li class="chapter" data-level="10.3.2" data-path="purrr-map.html"><a href="purrr-map.html#案例-5"><i class="fa fa-check"></i><b>10.3.2</b> 案例</a></li>
</ul></li>
<li class="chapter" data-level="10.4" data-path="purrr-map2.html"><a href="purrr-map2.html"><i class="fa fa-check"></i><b>10.4</b> map2 系列函数</a></li>
<li class="chapter" data-level="10.5" data-path="purrr-multi-parameter.html"><a href="purrr-multi-parameter.html"><i class="fa fa-check"></i><b>10.5</b> pmap系列函数</a></li>
<li class="chapter" data-level="10.6" data-path="purrr-reduce.html"><a href="purrr-reduce.html"><i class="fa fa-check"></i><b>10.6</b> 归约累计函数</a>
<ul>
<li class="chapter" data-level="10.6.1" data-path="purrr-reduce.html"><a href="purrr-reduce.html#reduce-函数"><i class="fa fa-check"></i><b>10.6.1</b> reduce 函数</a></li>
<li class="chapter" data-level="10.6.2" data-path="purrr-reduce.html"><a href="purrr-reduce.html#accumulate-函数"><i class="fa fa-check"></i><b>10.6.2</b> accumulate 函数</a></li>
</ul></li>
<li class="chapter" data-level="10.7" data-path="purrr-safely-functions.html"><a href="purrr-safely-functions.html"><i class="fa fa-check"></i><b>10.7</b> 安全函数</a></li>
<li class="chapter" data-level="10.8" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html"><i class="fa fa-check"></i><b>10.8</b> 其他函数介绍</a>
<ul>
<li class="chapter" data-level="10.8.1" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#flatten-系列"><i class="fa fa-check"></i><b>10.8.1</b> flatten 系列</a></li>
<li class="chapter" data-level="10.8.2" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#imap-函数"><i class="fa fa-check"></i><b>10.8.2</b> imap 函数</a></li>
<li class="chapter" data-level="10.8.3" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#walk-系列"><i class="fa fa-check"></i><b>10.8.3</b> walk 系列</a></li>
<li class="chapter" data-level="10.8.4" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#逻辑判断函数"><i class="fa fa-check"></i><b>10.8.4</b> 逻辑判断函数</a></li>
<li class="chapter" data-level="10.8.5" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#提取函数"><i class="fa fa-check"></i><b>10.8.5</b> 提取函数</a></li>
<li class="chapter" data-level="10.8.6" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#筛选函数"><i class="fa fa-check"></i><b>10.8.6</b> 筛选函数</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="11" data-path="self-define-function.html"><a href="self-define-function.html"><i class="fa fa-check"></i><b>11</b> 自定义函数</a>
<ul>
<li class="chapter" data-level="11.1" data-path="define-function-example.html"><a href="define-function-example.html"><i class="fa fa-check"></i><b>11.1</b> 简单示例</a></li>
<li class="chapter" data-level="11.2" data-path="define-function-conditional-execution.html"><a href="define-function-conditional-execution.html"><i class="fa fa-check"></i><b>11.2</b> 条件执行</a>
<ul>
<li class="chapter" data-level="11.2.1" data-path="define-function-conditional-execution.html"><a href="define-function-conditional-execution.html#多条件执行"><i class="fa fa-check"></i><b>11.2.1</b> 多条件执行</a></li>
</ul></li>
<li class="chapter" data-level="11.3" data-path="define-function-parameter.html"><a href="define-function-parameter.html"><i class="fa fa-check"></i><b>11.3</b> 函数参数</a>
<ul>
<li class="chapter" data-level="11.3.1" data-path="define-function-parameter.html"><a href="define-function-parameter.html#参数名称"><i class="fa fa-check"></i><b>11.3.1</b> 参数名称</a></li>
<li class="chapter" data-level="11.3.2" data-path="define-function-parameter.html"><a href="define-function-parameter.html#检查参数值"><i class="fa fa-check"></i><b>11.3.2</b> 检查参数值</a></li>
<li class="chapter" data-level="11.3.3" data-path="define-function-parameter.html"><a href="define-function-parameter.html#参数-5"><i class="fa fa-check"></i><b>11.3.3</b> …参数</a></li>
</ul></li>
<li class="chapter" data-level="11.4" data-path="function-return.html"><a href="function-return.html"><i class="fa fa-check"></i><b>11.4</b> 返回值</a>
<ul>
<li class="chapter" data-level="11.4.1" data-path="function-return.html"><a href="function-return.html#显式返回"><i class="fa fa-check"></i><b>11.4.1</b> 显式返回</a></li>
<li class="chapter" data-level="11.4.2" data-path="function-return.html"><a href="function-return.html#编写管道函数"><i class="fa fa-check"></i><b>11.4.2</b> 编写管道函数</a></li>
</ul></li>
<li class="chapter" data-level="11.5" data-path="function-environment.html"><a href="function-environment.html"><i class="fa fa-check"></i><b>11.5</b> 环境</a></li>
<li class="chapter" data-level="11.6" data-path="function-expand.html"><a href="function-expand.html"><i class="fa fa-check"></i><b>11.6</b> 拓展部分</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="file-system-operation.html"><a href="file-system-operation.html"><i class="fa fa-check"></i><b>12</b> R语言文件系统操作</a>
<ul>
<li class="chapter" data-level="12.1" data-path="file-base-r.html"><a href="file-base-r.html"><i class="fa fa-check"></i><b>12.1</b> base R</a>
<ul>
<li class="chapter" data-level="12.1.1" data-path="file-base-r.html"><a href="file-base-r.html#base:r-usage"><i class="fa fa-check"></i><b>12.1.1</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="12.2" data-path="fs-package.html"><a href="fs-package.html"><i class="fa fa-check"></i><b>12.2</b> fs package</a>
<ul>
<li class="chapter" data-level="12.2.1" data-path="fs-package.html"><a href="fs-package.html#fs-install"><i class="fa fa-check"></i><b>12.2.1</b> 安装</a></li>
<li class="chapter" data-level="12.2.2" data-path="fs-package.html"><a href="fs-package.html#fs-advanced"><i class="fa fa-check"></i><b>12.2.2</b> 优势</a></li>
<li class="chapter" data-level="12.2.3" data-path="fs-package.html"><a href="fs-package.html#fs-usage"><i class="fa fa-check"></i><b>12.2.3</b> 基础用法</a></li>
</ul></li>
<li class="chapter" data-level="12.3" data-path="fs-functions.html"><a href="fs-functions.html"><i class="fa fa-check"></i><b>12.3</b> fs函数介绍</a>
<ul>
<li class="chapter" data-level="12.3.1" data-path="fs-functions.html"><a href="fs-functions.html#fs-file-manipulation"><i class="fa fa-check"></i><b>12.3.1</b> 文件操作</a></li>
<li class="chapter" data-level="12.3.2" data-path="fs-functions.html"><a href="fs-functions.html#fs-dir-manipulation"><i class="fa fa-check"></i><b>12.3.2</b> 目录操作</a></li>
<li class="chapter" data-level="12.3.3" data-path="fs-functions.html"><a href="fs-functions.html#fs-link-manipulation"><i class="fa fa-check"></i><b>12.3.3</b> 链接操作</a></li>
<li class="chapter" data-level="12.3.4" data-path="fs-functions.html"><a href="fs-functions.html#fs-path-manipulation"><i class="fa fa-check"></i><b>12.3.4</b> 路径操作</a></li>
<li class="chapter" data-level="12.3.5" data-path="fs-functions.html"><a href="fs-functions.html#fs-help-manipulation"><i class="fa fa-check"></i><b>12.3.5</b> 辅助函数</a></li>
</ul></li>
<li class="chapter" data-level="12.4" data-path="file-base-fs-difference.html"><a href="file-base-fs-difference.html"><i class="fa fa-check"></i><b>12.4</b> base-fs-shell比较</a></li>
<li class="chapter" data-level="12.5" data-path="file-manipulation-reference-material.html"><a href="file-manipulation-reference-material.html"><i class="fa fa-check"></i><b>12.5</b> 参考资料</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://gitee.com/zhongyufei/Rbook" target="blank">gitee地址</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">商业数据分析师-R 语言数据处理</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="datatable:function" class="section level2" number="7.3">
<h2><span class="header-section-number">7.3</span> 常用函数</h2>
<p>常用函数指我们常用功能的函数，如排名、排序、非重复计数、判断、表连接、长宽转换等功能。</p>
<div id="特殊符号" class="section level3" number="7.3.1">
<h3><span class="header-section-number">7.3.1</span> 特殊符号</h3>
<p>.SD,.BY,.N,.I,.NGRP和.GRP,.SDcols等,只能用在 j 的位置,.N 可以用在 i 的位置。</p>
<p>如果想要记住用法需要自己多尝试练习，对于我来说.N使用较多。</p>
<div class="sourceCode" id="cb411"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb411-1"><a href="datatable-function.html#cb411-1" aria-hidden="true" tabindex="-1"></a>DT <span class="ot">=</span> <span class="fu">data.table</span>(<span class="at">x=</span><span class="fu">rep</span>(<span class="fu">c</span>(<span class="st">&quot;b&quot;</span>,<span class="st">&quot;a&quot;</span>,<span class="st">&quot;c&quot;</span>),<span class="at">each=</span><span class="dv">3</span>), <span class="at">v=</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">2</span>), <span class="at">y=</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">3</span>,<span class="dv">6</span>), <span class="at">a=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">9</span>, <span class="at">b=</span><span class="dv">9</span><span class="sc">:</span><span class="dv">1</span>)</span>
<span id="cb411-2"><a href="datatable-function.html#cb411-2" aria-hidden="true" tabindex="-1"></a>DT</span>
<span id="cb411-3"><a href="datatable-function.html#cb411-3" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v y a b</span></span>
<span id="cb411-4"><a href="datatable-function.html#cb411-4" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 1 1 1 9</span></span>
<span id="cb411-5"><a href="datatable-function.html#cb411-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: b 1 3 2 8</span></span>
<span id="cb411-6"><a href="datatable-function.html#cb411-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3: b 1 6 3 7</span></span>
<span id="cb411-7"><a href="datatable-function.html#cb411-7" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 4: a 2 1 4 6</span></span>
<span id="cb411-8"><a href="datatable-function.html#cb411-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 5: a 2 3 5 5</span></span>
<span id="cb411-9"><a href="datatable-function.html#cb411-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 6: a 1 6 6 4</span></span>
<span id="cb411-10"><a href="datatable-function.html#cb411-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 7: c 1 1 7 3</span></span>
<span id="cb411-11"><a href="datatable-function.html#cb411-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 8: c 2 3 8 2</span></span>
<span id="cb411-12"><a href="datatable-function.html#cb411-12" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 9: c 2 6 9 1</span></span>
<span id="cb411-13"><a href="datatable-function.html#cb411-13" aria-hidden="true" tabindex="-1"></a>X <span class="ot">=</span> <span class="fu">data.table</span>(<span class="at">x=</span><span class="fu">c</span>(<span class="st">&quot;c&quot;</span>,<span class="st">&quot;b&quot;</span>), <span class="at">v=</span><span class="dv">8</span><span class="sc">:</span><span class="dv">7</span>, <span class="at">foo=</span><span class="fu">c</span>(<span class="dv">4</span>,<span class="dv">2</span>))</span>
<span id="cb411-14"><a href="datatable-function.html#cb411-14" aria-hidden="true" tabindex="-1"></a>X</span>
<span id="cb411-15"><a href="datatable-function.html#cb411-15" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v foo</span></span>
<span id="cb411-16"><a href="datatable-function.html#cb411-16" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: c 8   4</span></span>
<span id="cb411-17"><a href="datatable-function.html#cb411-17" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: b 7   2</span></span>
<span id="cb411-18"><a href="datatable-function.html#cb411-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb411-19"><a href="datatable-function.html#cb411-19" aria-hidden="true" tabindex="-1"></a><span class="co"># 用在i的位置</span></span>
<span id="cb411-20"><a href="datatable-function.html#cb411-20" aria-hidden="true" tabindex="-1"></a>DT[.N] <span class="co">#取DT最后一行,.N 计数函数</span></span>
<span id="cb411-21"><a href="datatable-function.html#cb411-21" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v y a b</span></span>
<span id="cb411-22"><a href="datatable-function.html#cb411-22" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: c 2 6 9 1</span></span>
<span id="cb411-23"><a href="datatable-function.html#cb411-23" aria-hidden="true" tabindex="-1"></a>DT[,.N] <span class="co">#DT 共有多少行记录 返回一个整数</span></span>
<span id="cb411-24"><a href="datatable-function.html#cb411-24" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 9</span></span>
<span id="cb411-25"><a href="datatable-function.html#cb411-25" aria-hidden="true" tabindex="-1"></a>DT[, .N, by<span class="ot">=</span>x]  <span class="co">#分组计数</span></span>
<span id="cb411-26"><a href="datatable-function.html#cb411-26" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x N</span></span>
<span id="cb411-27"><a href="datatable-function.html#cb411-27" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 3</span></span>
<span id="cb411-28"><a href="datatable-function.html#cb411-28" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: a 3</span></span>
<span id="cb411-29"><a href="datatable-function.html#cb411-29" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3: c 3</span></span>
<span id="cb411-30"><a href="datatable-function.html#cb411-30" aria-hidden="true" tabindex="-1"></a>DT[, .SD, .SDcols<span class="ot">=</span>x<span class="sc">:</span>y]  <span class="co"># 选择x 到y 列</span></span>
<span id="cb411-31"><a href="datatable-function.html#cb411-31" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v y</span></span>
<span id="cb411-32"><a href="datatable-function.html#cb411-32" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 1 1</span></span>
<span id="cb411-33"><a href="datatable-function.html#cb411-33" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: b 1 3</span></span>
<span id="cb411-34"><a href="datatable-function.html#cb411-34" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3: b 1 6</span></span>
<span id="cb411-35"><a href="datatable-function.html#cb411-35" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 4: a 2 1</span></span>
<span id="cb411-36"><a href="datatable-function.html#cb411-36" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 5: a 2 3</span></span>
<span id="cb411-37"><a href="datatable-function.html#cb411-37" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 6: a 1 6</span></span>
<span id="cb411-38"><a href="datatable-function.html#cb411-38" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 7: c 1 1</span></span>
<span id="cb411-39"><a href="datatable-function.html#cb411-39" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 8: c 2 3</span></span>
<span id="cb411-40"><a href="datatable-function.html#cb411-40" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 9: c 2 6</span></span>
<span id="cb411-41"><a href="datatable-function.html#cb411-41" aria-hidden="true" tabindex="-1"></a><span class="co">#DT[, .SD, .SDcols=c(&quot;x&quot;,&quot;y&quot;)] 与上面不一样</span></span>
<span id="cb411-42"><a href="datatable-function.html#cb411-42" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb411-43"><a href="datatable-function.html#cb411-43" aria-hidden="true" tabindex="-1"></a>DT[, .SD[<span class="dv">1</span>]] <span class="co">#取第一行</span></span>
<span id="cb411-44"><a href="datatable-function.html#cb411-44" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v y a b</span></span>
<span id="cb411-45"><a href="datatable-function.html#cb411-45" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 1 1 1 9</span></span>
<span id="cb411-46"><a href="datatable-function.html#cb411-46" aria-hidden="true" tabindex="-1"></a>DT[, .SD[<span class="dv">1</span>], by<span class="ot">=</span>x] <span class="co">#按x列分组后</span></span>
<span id="cb411-47"><a href="datatable-function.html#cb411-47" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x v y a b</span></span>
<span id="cb411-48"><a href="datatable-function.html#cb411-48" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 1 1 1 9</span></span>
<span id="cb411-49"><a href="datatable-function.html#cb411-49" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: a 2 1 4 6</span></span>
<span id="cb411-50"><a href="datatable-function.html#cb411-50" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3: c 1 1 7 3</span></span>
<span id="cb411-51"><a href="datatable-function.html#cb411-51" aria-hidden="true" tabindex="-1"></a>DT[, <span class="fu">c</span>(.N, <span class="fu">lapply</span>(.SD, sum)), by<span class="ot">=</span>x] <span class="co">#按照x分组后 行数计数和每列求和</span></span>
<span id="cb411-52"><a href="datatable-function.html#cb411-52" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    x N v  y  a  b</span></span>
<span id="cb411-53"><a href="datatable-function.html#cb411-53" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1: b 3 3 10  6 24</span></span>
<span id="cb411-54"><a href="datatable-function.html#cb411-54" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2: a 3 5 10 15 15</span></span>
<span id="cb411-55"><a href="datatable-function.html#cb411-55" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3: c 3 5 10 24  6</span></span></code></pre></div>
</div>
<div id="排序函数-1" class="section level3" number="7.3.2">
<h3><span class="header-section-number">7.3.2</span> 排序函数</h3>
<p><code>frank</code>和<code>frankv</code>函数参数如下：</p>
<div class="sourceCode" id="cb412"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb412-1"><a href="datatable-function.html#cb412-1" aria-hidden="true" tabindex="-1"></a><span class="fu">frank</span>(x, ..., <span class="at">na.last=</span><span class="cn">TRUE</span>, <span class="at">ties.method=</span><span class="fu">c</span>(<span class="st">&quot;average&quot;</span>,</span>
<span id="cb412-2"><a href="datatable-function.html#cb412-2" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;first&quot;</span>, <span class="st">&quot;last&quot;</span>, <span class="st">&quot;random&quot;</span>, <span class="st">&quot;max&quot;</span>, <span class="st">&quot;min&quot;</span>, <span class="st">&quot;dense&quot;</span>))</span>
<span id="cb412-3"><a href="datatable-function.html#cb412-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb412-4"><a href="datatable-function.html#cb412-4" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x, <span class="at">cols=</span><span class="fu">seq_along</span>(x), <span class="at">order=</span>1L, <span class="at">na.last=</span><span class="cn">TRUE</span>,</span>
<span id="cb412-5"><a href="datatable-function.html#cb412-5" aria-hidden="true" tabindex="-1"></a>      <span class="at">ties.method=</span><span class="fu">c</span>(<span class="st">&quot;average&quot;</span>, <span class="st">&quot;first&quot;</span>, <span class="st">&quot;random&quot;</span>,</span>
<span id="cb412-6"><a href="datatable-function.html#cb412-6" aria-hidden="true" tabindex="-1"></a>        <span class="st">&quot;max&quot;</span>, <span class="st">&quot;min&quot;</span>, <span class="st">&quot;dense&quot;</span>))</span></code></pre></div>
<p>官方案例,如下所示:</p>
<div class="sourceCode" id="cb413"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb413-1"><a href="datatable-function.html#cb413-1" aria-hidden="true" tabindex="-1"></a><span class="co"># on vectors</span></span>
<span id="cb413-2"><a href="datatable-function.html#cb413-2" aria-hidden="true" tabindex="-1"></a>x <span class="ot">=</span> <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">1</span>, <span class="dv">4</span>, <span class="cn">NA</span>, <span class="dv">1</span>, <span class="cn">NA</span>, <span class="dv">4</span>)</span>
<span id="cb413-3"><a href="datatable-function.html#cb413-3" aria-hidden="true" tabindex="-1"></a><span class="co"># NAs are considered identical (unlike base R)</span></span>
<span id="cb413-4"><a href="datatable-function.html#cb413-4" aria-hidden="true" tabindex="-1"></a><span class="co"># default is average</span></span>
<span id="cb413-5"><a href="datatable-function.html#cb413-5" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x) <span class="co"># na.last=TRUE</span></span>
<span id="cb413-6"><a href="datatable-function.html#cb413-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0</span></span>
<span id="cb413-7"><a href="datatable-function.html#cb413-7" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x, <span class="at">na.last=</span><span class="cn">FALSE</span>)</span>
<span id="cb413-8"><a href="datatable-function.html#cb413-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 6.0 3.5 6.0 1.5 3.5 1.5 6.0</span></span>
<span id="cb413-9"><a href="datatable-function.html#cb413-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb413-10"><a href="datatable-function.html#cb413-10" aria-hidden="true" tabindex="-1"></a><span class="co"># on data.table</span></span>
<span id="cb413-11"><a href="datatable-function.html#cb413-11" aria-hidden="true" tabindex="-1"></a>DT <span class="ot">=</span> <span class="fu">data.table</span>(x, <span class="at">y=</span><span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="cn">NA</span>, <span class="dv">0</span>, <span class="dv">2</span>))</span>
<span id="cb413-12"><a href="datatable-function.html#cb413-12" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(DT, <span class="at">cols=</span><span class="st">&quot;x&quot;</span>) <span class="co"># same as frankv(x) from before</span></span>
<span id="cb413-13"><a href="datatable-function.html#cb413-13" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0</span></span>
<span id="cb413-14"><a href="datatable-function.html#cb413-14" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(DT, <span class="at">cols=</span><span class="st">&quot;x&quot;</span>, <span class="at">na.last=</span><span class="st">&quot;keep&quot;</span>)</span>
<span id="cb413-15"><a href="datatable-function.html#cb413-15" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0  NA 1.5  NA 4.0</span></span>
<span id="cb413-16"><a href="datatable-function.html#cb413-16" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(DT, <span class="at">cols=</span><span class="st">&quot;x&quot;</span>, <span class="at">ties.method=</span><span class="st">&quot;dense&quot;</span>, <span class="at">na.last=</span><span class="cn">NA</span>)</span>
<span id="cb413-17"><a href="datatable-function.html#cb413-17" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 2 1 2 1 2</span></span>
<span id="cb413-18"><a href="datatable-function.html#cb413-18" aria-hidden="true" tabindex="-1"></a><span class="fu">frank</span>(DT, x, <span class="at">ties.method=</span><span class="st">&quot;dense&quot;</span>, <span class="at">na.last=</span><span class="cn">NA</span>) <span class="co"># equivalent of above using frank</span></span>
<span id="cb413-19"><a href="datatable-function.html#cb413-19" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 2 1 2 1 2</span></span></code></pre></div>
<ul>
<li>frankv在排序时,NA被认为是一样的,基础base R 中认为不一样.</li>
</ul>
<div class="sourceCode" id="cb414"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb414-1"><a href="datatable-function.html#cb414-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span>  <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">1</span>, <span class="dv">4</span>, <span class="cn">NA</span>, <span class="dv">1</span>, <span class="cn">NA</span>, <span class="dv">4</span>) </span>
<span id="cb414-2"><a href="datatable-function.html#cb414-2" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x)</span>
<span id="cb414-3"><a href="datatable-function.html#cb414-3" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0</span></span>
<span id="cb414-4"><a href="datatable-function.html#cb414-4" aria-hidden="true" tabindex="-1"></a><span class="fu">rank</span>(x)</span>
<span id="cb414-5"><a href="datatable-function.html#cb414-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0 6.0 1.5 7.0 4.0</span></span></code></pre></div>
<ul>
<li>升序降序选择</li>
</ul>
<p>order参数只能为1或者-1.默认为1代表升序</p>
<div class="sourceCode" id="cb415"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb415-1"><a href="datatable-function.html#cb415-1" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">order =</span> 1L)</span>
<span id="cb415-2"><a href="datatable-function.html#cb415-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0</span></span>
<span id="cb415-3"><a href="datatable-function.html#cb415-3" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">order =</span> <span class="sc">-</span>1L)</span>
<span id="cb415-4"><a href="datatable-function.html#cb415-4" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 2.0 4.5 2.0 6.5 4.5 6.5 2.0</span></span></code></pre></div>
<ul>
<li>排序方式选择</li>
</ul>
<p>默认 average,还有dense,random,first,last,max,min等方式。其中dense是紧凑排名，random是随机让相同的随机排列后排名</p>
<div class="sourceCode" id="cb416"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb416-1"><a href="datatable-function.html#cb416-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>)</span>
<span id="cb416-2"><a href="datatable-function.html#cb416-2" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x)  <span class="co">#大小相同 排名相同,下一位排名除以2</span></span>
<span id="cb416-3"><a href="datatable-function.html#cb416-3" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">ties.method =</span> <span class="st">&#39;min&#39;</span>)  <span class="co">#大小相同 排名相同,取最小排名</span></span>
<span id="cb416-4"><a href="datatable-function.html#cb416-4" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">ties.method =</span> <span class="st">&#39;max&#39;</span>)  <span class="co">#大小相同 排名相同,取最大排名</span></span>
<span id="cb416-5"><a href="datatable-function.html#cb416-5" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">ties.method =</span> <span class="st">&#39;first&#39;</span>) <span class="co">#相同大小排名以后往后递增 根据实际情况决定</span></span>
<span id="cb416-6"><a href="datatable-function.html#cb416-6" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">ties.method =</span> <span class="st">&#39;dense&#39;</span>)</span>
<span id="cb416-7"><a href="datatable-function.html#cb416-7" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(x,<span class="at">ties.method =</span> <span class="st">&#39;random&#39;</span>)</span></code></pre></div>
<ul>
<li>NA处理</li>
</ul>
<p>默认是将NA排在最后,NAs是相同的，与base R 不一样。</p>
<p>na.last参数等于TRUE时，缺失值被排最后；如果等于FALSE,放在前面；如果等于NA，将被移除；如果等于“keep,”将会保留NA.</p>
<div class="sourceCode" id="cb417"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb417-1"><a href="datatable-function.html#cb417-1" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(<span class="fu">c</span>(<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>), <span class="at">na.last =</span> <span class="cn">TRUE</span>,<span class="at">ties.method =</span> <span class="st">&#39;first&#39;</span>)</span>
<span id="cb417-2"><a href="datatable-function.html#cb417-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 4 5 1 2 3</span></span>
<span id="cb417-3"><a href="datatable-function.html#cb417-3" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(<span class="fu">c</span>(<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>), <span class="at">na.last =</span> <span class="cn">FALSE</span>,<span class="at">ties.method =</span> <span class="st">&#39;first&#39;</span>)</span>
<span id="cb417-4"><a href="datatable-function.html#cb417-4" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 1 2 3 4 5</span></span>
<span id="cb417-5"><a href="datatable-function.html#cb417-5" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(<span class="fu">c</span>(<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>), <span class="at">na.last =</span> <span class="cn">NA</span>,<span class="at">ties.method =</span> <span class="st">&#39;first&#39;</span>)</span>
<span id="cb417-6"><a href="datatable-function.html#cb417-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 1 2 3</span></span>
<span id="cb417-7"><a href="datatable-function.html#cb417-7" aria-hidden="true" tabindex="-1"></a><span class="fu">frankv</span>(<span class="fu">c</span>(<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>), <span class="at">na.last =</span> <span class="st">&#39;keep&#39;</span>,<span class="at">ties.method =</span> <span class="st">&#39;first&#39;</span>)</span>
<span id="cb417-8"><a href="datatable-function.html#cb417-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] NA NA  1  2  3</span></span></code></pre></div>
</div>
<div id="非重复计数" class="section level3" number="7.3.3">
<h3><span class="header-section-number">7.3.3</span> 非重复计数</h3>
<p><code>uniqueN</code>相当于<code>length(unique(x))</code>,但是计算更快，内存效率更高。</p>
<div class="sourceCode" id="cb418"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb418-1"><a href="datatable-function.html#cb418-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span><span class="fu">sample</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>,<span class="dv">50</span>,<span class="at">replace =</span> <span class="cn">TRUE</span>)</span>
<span id="cb418-2"><a href="datatable-function.html#cb418-2" aria-hidden="true" tabindex="-1"></a><span class="fu">uniqueN</span>(x)</span>
<span id="cb418-3"><a href="datatable-function.html#cb418-3" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 10</span></span>
<span id="cb418-4"><a href="datatable-function.html#cb418-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb418-5"><a href="datatable-function.html#cb418-5" aria-hidden="true" tabindex="-1"></a>DT <span class="ot">&lt;-</span> <span class="fu">data.table</span>(<span class="at">A =</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>, <span class="at">each=</span><span class="dv">4</span>), <span class="at">B =</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>, <span class="at">each=</span><span class="dv">3</span>),</span>
<span id="cb418-6"><a href="datatable-function.html#cb418-6" aria-hidden="true" tabindex="-1"></a>                 <span class="at">C =</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>, <span class="dv">6</span>), <span class="at">key =</span> <span class="st">&quot;A,B&quot;</span>)</span>
<span id="cb418-7"><a href="datatable-function.html#cb418-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb418-8"><a href="datatable-function.html#cb418-8" aria-hidden="true" tabindex="-1"></a><span class="fu">uniqueN</span>(DT, <span class="at">by =</span> <span class="fu">key</span>(DT))</span>
<span id="cb418-9"><a href="datatable-function.html#cb418-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 6</span></span>
<span id="cb418-10"><a href="datatable-function.html#cb418-10" aria-hidden="true" tabindex="-1"></a><span class="fu">uniqueN</span>(DT)</span>
<span id="cb418-11"><a href="datatable-function.html#cb418-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] 10</span></span></code></pre></div>
</div>
<div id="判断函数" class="section level3" number="7.3.4">
<h3><span class="header-section-number">7.3.4</span> 判断函数</h3>
<ul>
<li>fifelse</li>
</ul>
<p>fifelse()类似<code>dplyr::if_else()</code>函数,相比base::ifelse() 更快。</p>
<div class="sourceCode" id="cb419"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb419-1"><a href="datatable-function.html#cb419-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span>  <span class="fu">c</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>, <span class="dv">3</span><span class="sc">:</span><span class="dv">2</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>,<span class="dv">5</span>)</span>
<span id="cb419-2"><a href="datatable-function.html#cb419-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fifelse</span>(x <span class="sc">&gt;</span> 2L, x, x <span class="sc">-</span> 1L)</span>
<span id="cb419-3"><a href="datatable-function.html#cb419-3" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  [1] 0 1 3 4 3 1 0 1 3 4 5</span></span>
<span id="cb419-4"><a href="datatable-function.html#cb419-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb419-5"><a href="datatable-function.html#cb419-5" aria-hidden="true" tabindex="-1"></a><span class="fu">fifelse</span>(x <span class="sc">&gt;</span> 2L,<span class="fu">fifelse</span>(x <span class="sc">&gt;=</span> 4L,x <span class="sc">+</span> 1L,x),x<span class="sc">-</span>1L)</span>
<span id="cb419-6"><a href="datatable-function.html#cb419-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  [1] 0 1 3 5 3 1 0 1 3 5 6</span></span></code></pre></div>
<ul>
<li>fcase</li>
</ul>
<p>与sql中的case when，与dplyr中的<code>case_when()</code>函数用法相似。相比fifelse相比，嵌套更加方便。</p>
<div class="sourceCode" id="cb420"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb420-1"><a href="datatable-function.html#cb420-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">=</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">10</span></span>
<span id="cb420-2"><a href="datatable-function.html#cb420-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fcase</span>(</span>
<span id="cb420-3"><a href="datatable-function.html#cb420-3" aria-hidden="true" tabindex="-1"></a>    x <span class="sc">&lt;</span> 5L, 1L,</span>
<span id="cb420-4"><a href="datatable-function.html#cb420-4" aria-hidden="true" tabindex="-1"></a>    x <span class="sc">&gt;</span> 5L, 3L</span>
<span id="cb420-5"><a href="datatable-function.html#cb420-5" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb420-6"><a href="datatable-function.html#cb420-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  [1]  1  1  1  1 NA  3  3  3  3  3</span></span>
<span id="cb420-7"><a href="datatable-function.html#cb420-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb420-8"><a href="datatable-function.html#cb420-8" aria-hidden="true" tabindex="-1"></a><span class="co"># not run 两种函数实现方式</span></span>
<span id="cb420-9"><a href="datatable-function.html#cb420-9" aria-hidden="true" tabindex="-1"></a><span class="fu">fifelse</span>(x <span class="sc">&gt;</span> <span class="dv">5</span>,<span class="fu">fifelse</span>(x <span class="sc">&gt;</span><span class="dv">8</span>,<span class="dv">2</span>,<span class="dv">1</span>),<span class="dv">0</span>)</span>
<span id="cb420-10"><a href="datatable-function.html#cb420-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  [1] 0 0 0 0 0 1 1 1 2 2</span></span>
<span id="cb420-11"><a href="datatable-function.html#cb420-11" aria-hidden="true" tabindex="-1"></a><span class="fu">fcase</span>(</span>
<span id="cb420-12"><a href="datatable-function.html#cb420-12" aria-hidden="true" tabindex="-1"></a>  x <span class="sc">&gt;</span> <span class="dv">8</span>,<span class="dv">2</span>,</span>
<span id="cb420-13"><a href="datatable-function.html#cb420-13" aria-hidden="true" tabindex="-1"></a>  x <span class="sc">&gt;</span> <span class="dv">5</span>,<span class="dv">1</span>,</span>
<span id="cb420-14"><a href="datatable-function.html#cb420-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">default =</span> <span class="dv">0</span></span>
<span id="cb420-15"><a href="datatable-function.html#cb420-15" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb420-16"><a href="datatable-function.html#cb420-16" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  [1] 0 0 0 0 0 1 1 1 2 2</span></span></code></pre></div>
</div>
<div id="交集-差集-合并" class="section level3" number="7.3.5">
<h3><span class="header-section-number">7.3.5</span> 交集 差集 合并</h3>
<p>相当于base R 中 union(),intersect(),setdiff() 和setequal() 功能.all参数控制如何处理重复的行,和SQL中不同的是,data.table将保留行顺序.</p>
<div class="sourceCode" id="cb421"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb421-1"><a href="datatable-function.html#cb421-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb421-2"><a href="datatable-function.html#cb421-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fintersect</span>(x, y, <span class="at">all =</span> <span class="cn">FALSE</span>)</span>
<span id="cb421-3"><a href="datatable-function.html#cb421-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetdiff</span>(x, y, <span class="at">all =</span> <span class="cn">FALSE</span>)</span>
<span id="cb421-4"><a href="datatable-function.html#cb421-4" aria-hidden="true" tabindex="-1"></a><span class="fu">funion</span>(x, y, <span class="at">all =</span> <span class="cn">FALSE</span>)</span>
<span id="cb421-5"><a href="datatable-function.html#cb421-5" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetequal</span>(x, y, <span class="at">all =</span> <span class="cn">TRUE</span>)</span>
<span id="cb421-6"><a href="datatable-function.html#cb421-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb421-7"><a href="datatable-function.html#cb421-7" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span>  <span class="fu">data.table</span>(<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">4</span>))</span>
<span id="cb421-8"><a href="datatable-function.html#cb421-8" aria-hidden="true" tabindex="-1"></a>x2 <span class="ot">&lt;-</span>  <span class="fu">data.table</span>(<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>)) <span class="co"># same set of rows as x</span></span>
<span id="cb421-9"><a href="datatable-function.html#cb421-9" aria-hidden="true" tabindex="-1"></a>y <span class="ot">&lt;-</span>  <span class="fu">data.table</span>(<span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">4</span>,<span class="dv">4</span>,<span class="dv">5</span>))</span>
<span id="cb421-10"><a href="datatable-function.html#cb421-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb421-11"><a href="datatable-function.html#cb421-11" aria-hidden="true" tabindex="-1"></a><span class="fu">fintersect</span>(x, y)            <span class="co"># intersect</span></span>
<span id="cb421-12"><a href="datatable-function.html#cb421-12" aria-hidden="true" tabindex="-1"></a><span class="fu">fintersect</span>(x, y, <span class="at">all=</span><span class="cn">TRUE</span>)  <span class="co"># intersect all</span></span>
<span id="cb421-13"><a href="datatable-function.html#cb421-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb421-14"><a href="datatable-function.html#cb421-14" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetdiff</span>(x, y)              <span class="co"># except</span></span>
<span id="cb421-15"><a href="datatable-function.html#cb421-15" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetdiff</span>(x, y, <span class="at">all=</span><span class="cn">TRUE</span>)    <span class="co"># except all</span></span>
<span id="cb421-16"><a href="datatable-function.html#cb421-16" aria-hidden="true" tabindex="-1"></a><span class="fu">funion</span>(x, y)                <span class="co"># union</span></span>
<span id="cb421-17"><a href="datatable-function.html#cb421-17" aria-hidden="true" tabindex="-1"></a><span class="fu">funion</span>(x, y, <span class="at">all=</span><span class="cn">TRUE</span>)      <span class="co"># union all</span></span>
<span id="cb421-18"><a href="datatable-function.html#cb421-18" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetequal</span>(x, x2, <span class="at">all=</span><span class="cn">FALSE</span>) <span class="co"># setequal</span></span>
<span id="cb421-19"><a href="datatable-function.html#cb421-19" aria-hidden="true" tabindex="-1"></a><span class="fu">fsetequal</span>(x, x2)            <span class="co"># setequal all</span></span></code></pre></div>
</div>
<div id="长宽转换" class="section level3" number="7.3.6">
<h3><span class="header-section-number">7.3.6</span> 长宽转换</h3>
<p>主要是两个函数<code>dcast</code>以及<code>melt</code>实现长宽转换，实现Excel中部分透视表功能。具体的函数参数请自行查阅文档。</p>
<ul>
<li>dcast函数能实现长转宽</li>
</ul>
<p>参数如下：fun.aggregate函数指定聚合函数，value.var参数指定参与聚合的字段。formula指定聚合维度，格式用x+y~z，其中x,y在行的位置，z在列的位置。</p>
<div class="sourceCode" id="cb422"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb422-1"><a href="datatable-function.html#cb422-1" aria-hidden="true" tabindex="-1"></a><span class="fu">dcast</span>(data, formula, <span class="at">fun.aggregate =</span> <span class="cn">NULL</span>, <span class="at">sep =</span> <span class="st">&quot;_&quot;</span>,</span>
<span id="cb422-2"><a href="datatable-function.html#cb422-2" aria-hidden="true" tabindex="-1"></a>    ..., <span class="at">margins =</span> <span class="cn">NULL</span>, <span class="at">subset =</span> <span class="cn">NULL</span>, <span class="at">fill =</span> <span class="cn">NULL</span>,</span>
<span id="cb422-3"><a href="datatable-function.html#cb422-3" aria-hidden="true" tabindex="-1"></a>    <span class="at">drop =</span> <span class="cn">TRUE</span>, <span class="at">value.var =</span> <span class="fu">guess</span>(data),</span>
<span id="cb422-4"><a href="datatable-function.html#cb422-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">verbose =</span> <span class="fu">getOption</span>(<span class="st">&quot;datatable.verbose&quot;</span>))</span></code></pre></div>
<p>示例如下：</p>
<div class="sourceCode" id="cb423"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb423-1"><a href="datatable-function.html#cb423-1" aria-hidden="true" tabindex="-1"></a>dt <span class="ot">&lt;-</span> <span class="fu">data.table</span>(分公司<span class="ot">=</span><span class="fu">rep</span>(<span class="fu">c</span>(<span class="st">&#39;华东&#39;</span>,<span class="st">&#39;华南&#39;</span>,<span class="st">&#39;华西&#39;</span>,<span class="st">&#39;华北&#39;</span>),<span class="dv">1000</span>),</span>
<span id="cb423-2"><a href="datatable-function.html#cb423-2" aria-hidden="true" tabindex="-1"></a>              季度<span class="ot">=</span><span class="fu">rep</span>(<span class="fu">c</span>(<span class="st">&#39;一季度&#39;</span>,<span class="st">&#39;二季度&#39;</span>,<span class="st">&#39;三季度&#39;</span>,<span class="st">&#39;四季度&#39;</span>),<span class="dv">1000</span>),</span>
<span id="cb423-3"><a href="datatable-function.html#cb423-3" aria-hidden="true" tabindex="-1"></a>              销售额<span class="ot">=</span><span class="fu">sample</span>(<span class="dv">100</span><span class="sc">:</span><span class="dv">200</span>,<span class="dv">4000</span>,<span class="at">replace =</span> <span class="cn">TRUE</span>))</span>
<span id="cb423-4"><a href="datatable-function.html#cb423-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dcast</span>(dt,分公司<span class="sc">~</span>季度,<span class="at">value.var =</span> <span class="st">&quot;销售额&quot;</span>,<span class="at">fun.aggregate =</span> sum)</span>
<span id="cb423-5"><a href="datatable-function.html#cb423-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;    分公司 一季度 三季度 二季度 四季度</span></span>
<span id="cb423-6"><a href="datatable-function.html#cb423-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1:   华东 149470      0      0      0</span></span>
<span id="cb423-7"><a href="datatable-function.html#cb423-7" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2:   华北      0      0      0 149343</span></span>
<span id="cb423-8"><a href="datatable-function.html#cb423-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3:   华南      0      0 150489      0</span></span>
<span id="cb423-9"><a href="datatable-function.html#cb423-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 4:   华西      0 150698      0      0</span></span></code></pre></div>
<p>从版本V1.9.6起可以同时对多个值实现不同聚合后的长转宽。</p>
<p>fun参数即 fun.aggregate的简写，可以是自定义的函数。</p>
<div class="sourceCode" id="cb424"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb424-1"><a href="datatable-function.html#cb424-1" aria-hidden="true" tabindex="-1"></a>dt <span class="ot">&lt;-</span>  <span class="fu">data.table</span>(<span class="at">x=</span><span class="fu">sample</span>(<span class="dv">5</span>,<span class="dv">20</span>,<span class="cn">TRUE</span>), <span class="at">y=</span><span class="fu">sample</span>(<span class="dv">2</span>,<span class="dv">20</span>,<span class="cn">TRUE</span>),</span>
<span id="cb424-2"><a href="datatable-function.html#cb424-2" aria-hidden="true" tabindex="-1"></a>                <span class="at">z=</span><span class="fu">sample</span>(letters[<span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>], <span class="dv">20</span>,<span class="cn">TRUE</span>), <span class="at">d1 =</span> <span class="fu">runif</span>(<span class="dv">20</span>), <span class="at">d2=</span>1L)</span>
<span id="cb424-3"><a href="datatable-function.html#cb424-3" aria-hidden="true" tabindex="-1"></a><span class="fu">dcast</span>(dt, x <span class="sc">+</span> y <span class="sc">~</span> z, <span class="at">fun=</span><span class="fu">list</span>(sum,mean), <span class="at">value.var=</span><span class="fu">c</span>(<span class="st">&quot;d1&quot;</span>,<span class="st">&quot;d2&quot;</span>))</span>
<span id="cb424-4"><a href="datatable-function.html#cb424-4" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;     x y d1_sum_a d1_sum_b d2_sum_a d2_sum_b d1_mean_a d1_mean_b d2_mean_a</span></span>
<span id="cb424-5"><a href="datatable-function.html#cb424-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  1: 1 1   0.8454   0.3717        1        2    0.8454    0.1858         1</span></span>
<span id="cb424-6"><a href="datatable-function.html#cb424-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  2: 1 2   0.3769   0.0000        1        0    0.3769       NaN         1</span></span>
<span id="cb424-7"><a href="datatable-function.html#cb424-7" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  3: 2 1   1.3419   0.4810        2        1    0.6709    0.4810         1</span></span>
<span id="cb424-8"><a href="datatable-function.html#cb424-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  4: 2 2   0.0000   0.6666        0        1       NaN    0.6666       NaN</span></span>
<span id="cb424-9"><a href="datatable-function.html#cb424-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  5: 3 1   0.8703   0.1866        1        1    0.8703    0.1866         1</span></span>
<span id="cb424-10"><a href="datatable-function.html#cb424-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  6: 3 2   0.0000   0.9074        0        2       NaN    0.4537       NaN</span></span>
<span id="cb424-11"><a href="datatable-function.html#cb424-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  7: 4 1   0.0957   0.0000        1        0    0.0957       NaN         1</span></span>
<span id="cb424-12"><a href="datatable-function.html#cb424-12" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  8: 4 2   0.1103   0.1867        1        1    0.1103    0.1867         1</span></span>
<span id="cb424-13"><a href="datatable-function.html#cb424-13" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  9: 5 1   1.1344   0.0000        2        0    0.5672       NaN         1</span></span>
<span id="cb424-14"><a href="datatable-function.html#cb424-14" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 10: 5 2   1.0839   0.0707        2        1    0.5419    0.0707         1</span></span>
<span id="cb424-15"><a href="datatable-function.html#cb424-15" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;     d2_mean_b</span></span>
<span id="cb424-16"><a href="datatable-function.html#cb424-16" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  1:         1</span></span>
<span id="cb424-17"><a href="datatable-function.html#cb424-17" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  2:       NaN</span></span>
<span id="cb424-18"><a href="datatable-function.html#cb424-18" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  3:         1</span></span>
<span id="cb424-19"><a href="datatable-function.html#cb424-19" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  4:         1</span></span>
<span id="cb424-20"><a href="datatable-function.html#cb424-20" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  5:         1</span></span>
<span id="cb424-21"><a href="datatable-function.html#cb424-21" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  6:         1</span></span>
<span id="cb424-22"><a href="datatable-function.html#cb424-22" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  7:       NaN</span></span>
<span id="cb424-23"><a href="datatable-function.html#cb424-23" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  8:         1</span></span>
<span id="cb424-24"><a href="datatable-function.html#cb424-24" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  9:       NaN</span></span>
<span id="cb424-25"><a href="datatable-function.html#cb424-25" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 10:         1</span></span>
<span id="cb424-26"><a href="datatable-function.html#cb424-26" aria-hidden="true" tabindex="-1"></a><span class="fu">dcast</span>(dt, x <span class="sc">+</span> y <span class="sc">~</span> z, <span class="at">fun=</span><span class="fu">list</span>(sum,mean), <span class="at">value.var=</span><span class="fu">list</span>(<span class="st">&quot;d1&quot;</span>,<span class="st">&quot;d2&quot;</span>)) <span class="co">#注意value.var是向量和列表时的区别</span></span>
<span id="cb424-27"><a href="datatable-function.html#cb424-27" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;     x y d1_sum_a d1_sum_b d2_mean_a d2_mean_b</span></span>
<span id="cb424-28"><a href="datatable-function.html#cb424-28" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  1: 1 1   0.8454   0.3717         1         1</span></span>
<span id="cb424-29"><a href="datatable-function.html#cb424-29" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  2: 1 2   0.3769   0.0000         1       NaN</span></span>
<span id="cb424-30"><a href="datatable-function.html#cb424-30" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  3: 2 1   1.3419   0.4810         1         1</span></span>
<span id="cb424-31"><a href="datatable-function.html#cb424-31" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  4: 2 2   0.0000   0.6666       NaN         1</span></span>
<span id="cb424-32"><a href="datatable-function.html#cb424-32" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  5: 3 1   0.8703   0.1866         1         1</span></span>
<span id="cb424-33"><a href="datatable-function.html#cb424-33" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  6: 3 2   0.0000   0.9074       NaN         1</span></span>
<span id="cb424-34"><a href="datatable-function.html#cb424-34" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  7: 4 1   0.0957   0.0000         1       NaN</span></span>
<span id="cb424-35"><a href="datatable-function.html#cb424-35" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  8: 4 2   0.1103   0.1867         1         1</span></span>
<span id="cb424-36"><a href="datatable-function.html#cb424-36" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  9: 5 1   1.1344   0.0000         1       NaN</span></span>
<span id="cb424-37"><a href="datatable-function.html#cb424-37" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 10: 5 2   1.0839   0.0707         1         1</span></span></code></pre></div>
<ul>
<li>melt函数实现宽转长</li>
</ul>
<div class="sourceCode" id="cb425"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb425-1"><a href="datatable-function.html#cb425-1" aria-hidden="true" tabindex="-1"></a><span class="fu">melt</span>(data, id.vars, measure.vars,</span>
<span id="cb425-2"><a href="datatable-function.html#cb425-2" aria-hidden="true" tabindex="-1"></a>    <span class="at">variable.name =</span> <span class="st">&quot;variable&quot;</span>, <span class="at">value.name =</span> <span class="st">&quot;value&quot;</span>,</span>
<span id="cb425-3"><a href="datatable-function.html#cb425-3" aria-hidden="true" tabindex="-1"></a>    ..., <span class="at">na.rm =</span> <span class="cn">FALSE</span>, <span class="at">variable.factor =</span> <span class="cn">TRUE</span>,</span>
<span id="cb425-4"><a href="datatable-function.html#cb425-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">value.factor =</span> <span class="cn">FALSE</span>,</span>
<span id="cb425-5"><a href="datatable-function.html#cb425-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">verbose =</span> <span class="fu">getOption</span>(<span class="st">&quot;datatable.verbose&quot;</span>))</span></code></pre></div>
<p>示例如下:</p>
<div class="sourceCode" id="cb426"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb426-1"><a href="datatable-function.html#cb426-1" aria-hidden="true" tabindex="-1"></a>ChickWeight <span class="ot">=</span> <span class="fu">as.data.table</span>(ChickWeight)</span>
<span id="cb426-2"><a href="datatable-function.html#cb426-2" aria-hidden="true" tabindex="-1"></a><span class="fu">setnames</span>(ChickWeight, <span class="fu">tolower</span>(<span class="fu">names</span>(ChickWeight)))</span>
<span id="cb426-3"><a href="datatable-function.html#cb426-3" aria-hidden="true" tabindex="-1"></a>DT <span class="ot">&lt;-</span> <span class="fu">melt</span>(<span class="fu">as.data.table</span>(ChickWeight), <span class="at">id=</span><span class="dv">2</span><span class="sc">:</span><span class="dv">4</span>) <span class="co"># calls melt.data.table</span></span>
<span id="cb426-4"><a href="datatable-function.html#cb426-4" aria-hidden="true" tabindex="-1"></a>DT</span>
<span id="cb426-5"><a href="datatable-function.html#cb426-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;      time chick diet variable value</span></span>
<span id="cb426-6"><a href="datatable-function.html#cb426-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   1:    0     1    1   weight    42</span></span>
<span id="cb426-7"><a href="datatable-function.html#cb426-7" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   2:    2     1    1   weight    51</span></span>
<span id="cb426-8"><a href="datatable-function.html#cb426-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   3:    4     1    1   weight    59</span></span>
<span id="cb426-9"><a href="datatable-function.html#cb426-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   4:    6     1    1   weight    64</span></span>
<span id="cb426-10"><a href="datatable-function.html#cb426-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   5:    8     1    1   weight    76</span></span>
<span id="cb426-11"><a href="datatable-function.html#cb426-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;  ---                               </span></span>
<span id="cb426-12"><a href="datatable-function.html#cb426-12" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 574:   14    50    4   weight   175</span></span>
<span id="cb426-13"><a href="datatable-function.html#cb426-13" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 575:   16    50    4   weight   205</span></span>
<span id="cb426-14"><a href="datatable-function.html#cb426-14" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 576:   18    50    4   weight   234</span></span>
<span id="cb426-15"><a href="datatable-function.html#cb426-15" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 577:   20    50    4   weight   264</span></span>
<span id="cb426-16"><a href="datatable-function.html#cb426-16" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 578:   21    50    4   weight   264</span></span></code></pre></div>
</div>
<div id="表连接" class="section level3" number="7.3.7">
<h3><span class="header-section-number">7.3.7</span> 表连接</h3>
<p>两个数据框之间左连,右连等操作,类似数据库中的left_join right_join,inner_join 等函数.</p>
<p>键入?merge()查看函数帮助,data.table 包中和base R 中都有merge 函数,当第一个数据框是data.table格式时启用data.table::merge().</p>
<div class="sourceCode" id="cb427"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb427-1"><a href="datatable-function.html#cb427-1" aria-hidden="true" tabindex="-1"></a>?<span class="fu">merge</span>()</span>
<span id="cb427-2"><a href="datatable-function.html#cb427-2" aria-hidden="true" tabindex="-1"></a><span class="fu">merge</span>(x, y, <span class="at">by =</span> <span class="cn">NULL</span>, <span class="at">by.x =</span> <span class="cn">NULL</span>, <span class="at">by.y =</span> <span class="cn">NULL</span>, <span class="at">all =</span> <span class="cn">FALSE</span>,</span>
<span id="cb427-3"><a href="datatable-function.html#cb427-3" aria-hidden="true" tabindex="-1"></a><span class="at">all.x =</span> all, <span class="at">all.y =</span> all, <span class="at">sort =</span> <span class="cn">TRUE</span>, <span class="at">suffixes =</span> <span class="fu">c</span>(<span class="st">&quot;.x&quot;</span>, <span class="st">&quot;.y&quot;</span>), <span class="at">no.dups =</span> <span class="cn">TRUE</span>,</span>
<span id="cb427-4"><a href="datatable-function.html#cb427-4" aria-hidden="true" tabindex="-1"></a><span class="at">allow.cartesian=</span><span class="fu">getOption</span>(<span class="st">&quot;datatable.allow.cartesian&quot;</span>),  <span class="co"># default FALSE</span></span>
<span id="cb427-5"><a href="datatable-function.html#cb427-5" aria-hidden="true" tabindex="-1"></a>...)</span></code></pre></div>
<p>x.y为连个数据框,当两个数据框连接字段相同时,用by=c(’‘,’’)连接,不同时采用,by.x=,by.y= ,all,all.x,all.y等参数决定连接方式,sort 默认为排序,当不需要排序时更改参数,allow.cartesian=是否允许笛卡尔,默认不允许,当需要时设置为TURE.</p>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="datatable-usage.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="datatable-advanced-functions.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["Data-Handling-in-R.pdf", "Data-Handling-in-R.epub"],
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
